home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
pt20pc.zip
/
COMMAND.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-18
|
17KB
|
696 lines
#include "pt.h"
#include "malloc.h"
#include "string.h"
#include "process.h"
#include "io.h"
#include "stdlib.h"
#include "conio.h"
#define STACKSIZE 2048
int pascal
/* XTAG:command */
command(fn, c, w)
int fn;
unsigned char c;
register struct window *w;
{
extern unsigned char msgBuffer[];
extern unsigned char textBuffer[];
extern int debug;
extern struct window *selWindow;
extern struct window *activeWindow;
extern long selBegin, selEnd;
extern union REGS rin, rout;
extern int overType;
extern int searchMode;
extern int realSearchMode;
extern int mousePresent;
extern int scrRows, scrCols;
extern int i43lines;
extern unsigned char buttonVector[];
extern int menuRow, menuCol;
extern int lastOnTopline;
extern int lastCommand;
extern int macroIndex;
extern int macroSize;
extern int macroState;
extern int selMode;
extern int lastFn;
/* extern int errno; */
#ifdef OVERLAYS
extern int filesToOpen;
extern int primaryFilesToOpen;
extern struct openFile *ffsToOpen[];
extern unsigned char *overlayMap[];
extern unsigned char *stktop;
extern unsigned char primaryOverlay[];
extern unsigned char secondaryOverlay[];
extern unsigned char overlayString[];
extern unsigned char *overlayArguments;
extern int overlayState;
extern int quitExecuted;
#endif
extern unsigned char *userMessages[];
extern struct openFile *files;
extern unsigned char maxTextCycles;
extern unsigned char maxBorderCycles;
extern struct SREGS segRegs;
extern struct menuBlock far *menus[];
extern struct optionItem options[];
extern unsigned char saveVideoMode;
extern union REGS rin, rout;
extern unsigned int dispMemory;
int row1, col1;
int r1, r2;
int i, n;
long cp;
unsigned char ch;
unsigned char *fileName;
struct window *w2;
unsigned char *s, buffer[64];
#ifdef OVERLAYS
unsigned char *userArgs;
unsigned char *saveStktop;
#endif
/* since we are about to issue a command, we do not need to erase */
/* the command description on the top line (so don't) */
lastOnTopline = 0;
startOver:
#ifdef OVERLAYS
if( 200 <= fn && fn <= 255 ) {
fileName = overlayMap[fn-200];
doOverlay:
n = strlen(fileName) - 1;
if( fileName[n] == ' ' )
userArgs = getInput("Execute: ", fileName, 5);
else
userArgs = fileName;
/* allow user to cancel */
if( userArgs == NULL ) {
msg("Command cancelled", 1);
goto returnLocation;
}
/* make a copy of the command line */
strncpy(overlayString, userArgs, 128);
overlayArguments = strchr(overlayString, ' ');
if( overlayArguments != NULL )
*overlayArguments++ = '\0';
else
overlayArguments = "";
/* see if this overlay is loaded and inactive */
/* see if this is a primary or secondary overlay */
n = strlen(overlayString) - 1;
if( overlayString[n] == '*' ) { /* primary overlay is to be loaded */
/* eliminate the '*' which means the overlay is primary */
overlayString[n] = '\0';
if( (overlayState & 0x1) != 0 ) {
/* a primary overlay is already loaded */
if( strcmp(primaryOverlay, overlayString) == 0 ) {
/* same overlay, reactivate this one */
if( (overlayState & 0x2) != 0 ) {
strcpy(textBuffer, "0");
secondaryOverlay[0] = '\0';
overlayState &= ~0x2;
overlayState |= 0x14;
} else {
strcpy(textBuffer, overlayArguments);
}
} else {
/* remember the name of the new overlay */
strcpy(primaryOverlay, overlayString);
strcpy(textBuffer, "0");
/* indicate we are unloading a primary */
/* overlay */
overlayState |= 0x8;
/* check for secondary overlay */
if( (overlayState & 0x2) != 0 ) {
overlayState &= ~0x2;
overlayState |= 0x4;
secondaryOverlay[0] = '\0';
} else {
}
}
/* Drop out of command loop. This will return to */
/* "overlayDriver()" which will return (from the */
/* software interrupt)to the overlay. */
return 1;
} else {
strcpy(primaryOverlay, overlayString);
overlayState |= 0x1;
/* see if we have to unload the secondary overlay */
if( (overlayState & 0x2) != 0 ) {
strcpy(textBuffer, "0");
overlayState &= ~0x2;
overlayState |= 0x4;
secondaryOverlay[0] = '\0';
return 1;
}
/* else, drop though and load the overlay */
}
} else { /* secondary overlay is to be loaded */
if( (overlayState & 0x2) != 0 ) {
/* a secondary overlay is already loaded */
if( strcmp(secondaryOverlay, overlayString) == 0 ) {
/* same overlay, reactivate this one */
strcpy(textBuffer, overlayArguments);
} else {
/* different overlay, unload this one */
/* 0 argument means to exit the overlay */
strcpy(textBuffer, "0");
strcpy(secondaryOverlay, overlayString);
/* indicate we are unloading an overlay */
overlayState |= 0x4;
}
/* Drop out of command loop. This will return to */
/* "overlayDriver()" which will return (from the */
/* software interrupt)to the overlay. */
return 1;
} else {
strcpy(secondaryOverlay, overlayString);
overlayState |= 0x2;
/* drop though and load the overlay */
}
}
retryOverlay:
/* save the old value of stktop */
saveStktop = stktop;
/* set up the stack to use when the overlay calls us back */
stktop = malloc(STACKSIZE);
if( stktop == NULL ) {
msg(userMessages[NOSPACEMSG], 3);
goto returnLocation;
}
stktop += STACKSIZE-8;
/* We have to reopen any files opened by the overlay when it */
/* exits since DOS will close them automatically. If fileToOpen */
/* is already non-zero then an overlay is already loaded. */
if( filesToOpen == 0 )
filesToOpen = 1;
else
primaryFilesToOpen = filesToOpen;
n = spawnlp(0, overlayString, overlayString, overlayArguments, NULL);
if( n == -1 ) {
sprintf(msgBuffer,
"Overlay %s could NOT be executed [Press any key to continue]",
overlayString);
msg(msgBuffer, 3);
} else if( n > 0 ) {
sprintf(msgBuffer, "Overlay %s returned error code of 0x%X",
overlayString, n);
msg(msgBuffer, 1);
}
/* free up the stack space */
stktop -= STACKSIZE-8;
free(stktop);
/* now restore the previous value of stktop */
stktop = saveStktop;
/* reopen any files that were opened during the overlay */
/* since DOS will have closed them automatically */
/* if this is a secondary overlay that is exiting, then only */
/* reopen the files that were opened since the secondary */
/* overlay was loaded */
if( primaryFilesToOpen > 0 )
n = primaryFilesToOpen;
else
n = 1;
for(i = n; i < filesToOpen; ++i) {
ff = ffsToOpen[i-1];
ff->origHandle = openls(ff->origName, 0);
}
if( primaryFilesToOpen > 0 ) {
filesToOpen = primaryFilesToOpen;
primaryFilesToOpen = 0;
} else
filesToOpen = 0;
if( quitExecuted )
return 1;
if( (overlayState & 0x4) != 0 ) {
/* see if we have to unload the primary overlay also */
overlayState &= ~0x4;
if( (overlayState & 0x8) != 0 ) {
strcpy(textBuffer, "0"); /* unload overlay arg. */
return 1;
}
if( (overlayState & 0x10) != 0 ) {
overlayState &= ~0x10;
strcpy(textBuffer, overlayArguments);
return 1;
}
goto retryOverlay;
} else if( (overlayState & 0x8) != 0 ) {
overlayState &= ~0x8;
goto retryOverlay;
} else if( (overlayState & 0x2) != 0 ) {
overlayState &= ~0x2;
secondaryOverlay[0] = '\0';
} else { /* overlayState == 0x1 (primary overlay only) */
primaryOverlay[0] = '\0';
overlayState = 0;
}
initMouse(5, 10, 0);
goto returnLocation;
}
#endif
if( fn < 50 ) {
n = command2(fn, c, w);
if( fn != FMOUSECOM1 && fn != FMOUSECOM2
&& fn != FDONOTHING && fn > 0 ) {
lastCommand = fn;
}
lastFn = fn;
if( n != 2 )
return n;
/* return value of 2 means that select and extend want the */
/* change menu command to be executed */
fn = FCHANGEMENU;
/* and drop through since change menu >= 50 */
}
/* else do commands 50 and up */
switch( fn ) {
case FAUTOSAVEINTERVAL:case FAUTOSCROLLRATE:case FAUTOINDENT:
case FBORDERCOLORS:case FCENTERMENUS:
ca